import { IElmentRoot } from "../../ADCore/Interfaces/IRole";
import { IEffect } from "../../ADCore/Interfaces/IEffect";
import ADQ from "../../ADCore/Core/ADQ";
import { LayerEnum } from "../../ADCore/Interfaces/IEnum";
import EffectBase from "./EffectBase";

/**小球拖尾动效 */
export default class TailingGenarator extends EffectBase implements IEffect {
    interval: number;
    constructor(imgurl, intervals) {
        super();
        this.layer=LayerEnum.effectGround;
        var sprite = new Laya.Sprite();
        sprite.loadImage(imgurl);
        sprite.pivot(16, 16);
        this.interval = intervals;
        this.spriteBase = sprite;
    }
    play() {
        var sprite = this.spriteBase;
        if (this.interval) {
            Laya.Tween.to(sprite, { alpha: 1 }, this.interval, Laya.Ease.circIn, Laya.Handler.create(this, () => {
                Laya.Tween.to(sprite, { alpha: 0, scaleX: 0, scaleY: 0 }, 1800, Laya.Ease.circIn, Laya.Handler.create(this, () => {
                    this.destroy();
                }));
            }));
        } else {
            Laya.Tween.to(sprite, { alpha: 0, scaleX: 0, scaleY: 0 }, 1800, Laya.Ease.circIn, Laya.Handler.create(this, () => {
                this.destroy();
            }));
        }
    }
     
}